/**
 * @Auther: lichao
 * @Date: 2024/10/16 - 10 - 16 - 20:19
 * @Description: PACKAGE_NAME
 * @version: 1.0
 */

import java.util.StringJoiner;

/**
 * @program: java
 *
 * @description: StringJoiner 类的 merge 方法
 *
 * @author: lichao
 *
 * @create: 2024-10-16 20:19
 **/

public class MergeTest {
    public static void main(String[] args) {
        /**
         *  merger 方法是用来合并两个的 StringJoiner
         *  被合并的 StringJoiner 的 prefix、suffix 两个参数将不起作用
         *  但是 delimiter 参数还是起作用，只是对自己 StringJoiner 里面的数据起作用
         */
        StringJoiner sj = new StringJoiner(",", "[", "]");
        sj.add("a").add("b").add("c");
        StringJoiner sj2 = new StringJoiner(",");
        sj2.add("d").add("e").add("f");
        sj.merge(sj2);
        System.out.println(sj.toString()); // [a,b,c,d,e,f]

        StringJoiner sj3 = new StringJoiner(",", "[", "]");
        sj3.add("a").add("b").add("c");
        StringJoiner sj4 = new StringJoiner(";");
        sj4.add("d").add("e").add("f");
        sj3.merge(sj4);
        System.out.println(sj3.toString()); // [a,b,c,d;e;f]

        StringJoiner sj5 = new StringJoiner(",", "[", "]");
        sj5.add("a").add("b").add("c");
        StringJoiner sj6 = new StringJoiner(";", "{", "}");
        sj6.add("d").add("e").add("f");
        sj5.merge(sj6);
        System.out.println(sj5.toString()); // [a,b,c,d;e;f]
    }
}
